package cn.fhkj.web.controller;

import cn.fhkj.entity.RenQiuZfPublicity;
import cn.fhkj.entity.RenQiuZfUnit;
import cn.fhkj.service.RenqiuZfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @program: renqiu-publicity-web
 * @description: 跳转控制器
 * @author: seven
 * @create: 2020-08-07 17:15
 **/
@RequestMapping("/")
@Controller
public class PageController extends BaseController{
    /**
     * 页面跳转
     */
    @RequestMapping("index")
    public static String index(){
        return "index";
    }
//    @RequestMapping("details")
//    public static String details(){
//        return "details";
//    }
    @Autowired
    private RenqiuZfService renqiuZfService;

    @RequestMapping("/details/{id}")
    public String detail(@PathVariable("id") Long publicityId, Model model){
        RenQiuZfPublicity renQiuZfPublicity = renqiuZfService.getPublicityById(publicityId);
        String title = renQiuZfPublicity.getTitle();
        String createTime = renQiuZfPublicity.getCreateTime();
        String resUrl = handleResToUrl(renQiuZfPublicity.getResUrl());
        Integer resType = renQiuZfPublicity.getResType();
        Long unitId = renQiuZfPublicity.getUnitId();
        RenQiuZfUnit unit = renqiuZfService.getUnitById(unitId);
        String unitName = "";
        if(unit != null){
            unitName = unit.getName();
        }
        model.addAttribute("title",title);
        model.addAttribute("createTime",createTime);
        model.addAttribute("resUrl",resUrl);
        model.addAttribute("resType",resType);
        model.addAttribute("unitName",unitName);
        model.addAttribute("id",publicityId);
        return "details";
    }
    @RequestMapping("list")
    public static String list(){
        return "list";
    }

    @RequestMapping(value = "page")
    public String page() {
        return "redirect:index";
    }

}
